package com.mop.app.common.enums;


import com.mop.app.common.exception.BizException;
import com.mop.app.common.exception.Message;

import java.util.Objects;

/**
 * 异常枚举类
 *
 * @author
 */
public enum AppBizEnums {
    SUCCESS("0000", "成功"),
    ERROR("9999", "失败"),

    ERROR_COMMON("9990", "网络异常"),

    ERROR_9996("9996", "登录异常"),
    ERROR_1000("1000", "用户名错误"),
    ERROR_1001("1001", "验证码错误，请重试"),
    ERROR_1002("1002", "账号异常"),
    ERROR_1003("1003", "未登录"),
    ERROR_1004("1004", "登录过于频繁，请勿频繁操作"),
    ERROR_1005("1005", "短信发送失败，请重试"),
    ERROR_1006("1006", "请输入正确的手机号"),
    ERROR_1007("1007", "用户未注册"),
    ERROR_1008("1008", "文件不能为空"),
    ERROR_1009("1009", "文件过大"),
    ERROR_1010("1010", "请上传正确的文件类型,如jpeg,gif,png"),
    ERROR_1011("1011", "文件上传失败"),
    ;
    private String code;
    private String desc;

    AppBizEnums(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String name) {
        this.desc = name;
    }

    public Message getMessage() {
        return new Message(this.code, this.getDesc());
    }

    public void assertTrue(boolean value) {
        if (value) {
            return;
        }
        throw new BizException(this.getCode(), this.getDesc());
    }

    public void assertNotNull(Object object) {
        if (Objects.nonNull(object)) {
            return;
        }
        throw new BizException(this.getCode(), this.getDesc());
    }
}
